<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function throttle(fn, delay) {
      let curTime = Date.now();

      return function () {
        let context = this,
          args = arguments,
          nowTime = Date.now();
        // 如果两次时间间隔超过了指定时间，则执行函数。
        if (nowTime - curTime >= delay) {
          curTime = Date.now();
          return fn.apply(context, args);
        }
      };
    }
  </script>
</body>

</html>